# Backend lifecycle

The backend lifecycle refers to the sequence of statuses that a backend managed by Plane passes through,
and defines Plane’s responsibilities at each stage.

The statuses are:

- `scheduled`: The Plane controller has chosen a drone to run the backend.
- `loading`: The drone has acknowledged the backend and is loading the appropriate image from the registry.
- `starting`: The drone has loaded the image and is starting the container.
- `waiting`: The container has started. The drone is waiting for it to listen on an HTTP port.
- `ready`: The container is listening on an HTTP port. The drone is ready to route traffic to it.
- `terminating`: The drone has sent a “soft” request to terminate the backend.
  The backend may remain in this state for a grace period (by default 10 seoconds) before being hard-terminated,
  unless it exits on its own first.
- `hard-terminating`: The drone has sent a “hard” request to terminate the backend.
- `terminated`: The drone has terminated the backend. This is considered the only terminal state.

A backend may skip over some of these statuses, but will only transition to statuses lower in the list, never
higher. Every backend will eventually reach the `terminated` state unless the drone responsible for it is
permanently lost.

Aside from assigning the initial `scheduled` status, the drone to which a backend is assigned is responsible for
reporting all status changes.

Statuses returned from the [status API](../plane-api.mdx#status-api) are returned as strings matching the
monospace string above; that is, they begin with a capital letter followed by lowercase letters.

## Backend termination:

There are four ways a backend can be terminated:

- It can exit on its own.
- A call to the [terminate API](../plane-api.mdx#terminate-api)
  (this is also how the CLI `terminate` command works).
- It can become idle for more than `max_idle_seconds` seconds, if one was provided
  when the backend was created.
- It can reach a deadline of `lifetime_limit_seconds` seconds after it was created,
  if one was provided when the backend was created.
